package com.bjb.vr.manager.controller;

import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.FileOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件操作列表
 *
 * @author: HuJingBo
 * @version 1.0.0
 * @time: 2022/4/14 13:39
 */
@RestController
@RequestMapping("/api/manager/v1")
public class FileOperationController {

    @Autowired
    private FileOperationService fileOperationService;

    /**
     * 文件上传--单个文件
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public BaseResult uploadFile(@RequestParam("fileName") MultipartFile file) throws IOException {
        if (file.getSize() == 0) {
            return CommonResult.Fail("文件不能为空");
        }
        String url = fileOperationService.uploadFile(file);
        return CommonResult.Ok("上传成功！").setResult(url);
    }

}
